﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace Citrix.XaAdminMobile.Resources
{
    /// <summary>
    /// Interaction logic for SmallLoadingAnimation.xaml
    /// </summary>
    public partial class SmallLoadingAnimation : UserControl
    {
        /// <summary>
        /// Used to perform the animation.
        /// </summary>
        private Storyboard storyboard;

        /// <summary>
        /// Ctor
        /// </summary>
        public SmallLoadingAnimation()
        {
            InitializeComponent();

            this.storyboard = this.TryFindResource("LoadingAnimation") as Storyboard;
        }

        /// <summary>
        /// Start/stop the animation based on the controls visibility.
        /// </summary>
        private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue && !(bool)e.OldValue)
            {
                if (null != this.storyboard)
                {
                    this.storyboard.Begin();
                }
            }
            if (!(bool)e.NewValue && (bool)e.OldValue)
            {
                if (null != this.storyboard)
                {
                    this.storyboard.Stop();
                }
            }
        }
    }
}
